/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.risk.control.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.risk.common.constant.enums.RiskModDictEnum;
import com.hopes.bizz.risk.common.constant.enums.RiskSysDictEnum;
import com.hopes.bizz.risk.control.bo.RiskUnitStopBO;
import com.hopes.bizz.risk.control.entity.RiskUnitEntity;
import com.hopes.bizz.risk.control.entity.RiskUnitStopEntity;
import com.hopes.bizz.risk.control.dto.RiskUnitStopExcelDTO;
import com.hopes.bizz.risk.control.mapper.RiskUnitMapper;
import com.hopes.bizz.risk.control.vo.RiskUnitStopExcelVO;
import com.hopes.bizz.risk.control.mapper.RiskUnitStopMapper;
import com.hopes.bizz.risk.control.service.RiskUnitStopService;
import com.hopes.bizz.risk.control.vo.RiskUnitStopVO;
import com.hopes.boss.admin.api.resolver.DictResolver;
import com.hopes.boss.common.entity.ValidateImportBO;
import com.hopes.boss.common.excel.vo.ErrorMessage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
/**
 * 装置停用检维修记录
 *
 * @author cx
 * @date 2023-07-17 19:39:27
 */
@Service
public class RiskUnitStopServiceImpl extends ServiceImpl<RiskUnitStopMapper, RiskUnitStopEntity> implements RiskUnitStopService {

    @Autowired
    private RiskUnitStopMapper riskUnitStopMapper;

    @Autowired
    private RiskUnitMapper riskUnitMapper;

    @Override
    public ValidateImportBO<RiskUnitStopExcelDTO> validateImport(List<RiskUnitStopExcelDTO> excelDTOList) {
        ValidateImportBO<RiskUnitStopExcelDTO> bo = new ValidateImportBO<>();
        List<ErrorMessage> errorMessageList = new ArrayList<>();
        List<RiskUnitStopExcelDTO> saveList = new ArrayList<>(excelDTOList);
        int successNum = excelDTOList.size();
        int failedNum = 0;

        bo.setErrorMessages(errorMessageList);
        bo.setSaveList(saveList);
        bo.setSuccessNum(successNum);
        bo.setFailedNum(failedNum);
        return bo;
    }

    @Override
    public RiskUnitStopEntity importDtoToEntity(RiskUnitStopExcelDTO excelDto) {
        RiskUnitStopEntity entity= new RiskUnitStopEntity();
        BeanUtils.copyProperties(excelDto, entity);
        return entity;
    }





    @Override
    public Object getRiskObjectById(Long id) {
      return riskUnitStopMapper.getRiskObjectById(id);
    }

    @Override
    public RiskUnitStopExcelVO exportEntityToVo(RiskUnitStopEntity entity) {
        RiskUnitStopExcelVO excelVO = new RiskUnitStopExcelVO();
        BeanUtils.copyProperties(entity, excelVO);
        Long objectIdByRiskUnitId = riskUnitMapper.getUnitVoById(entity.getRiskUnitId()).getRiskObjectId();
        excelVO.setRiskObjectId(DictResolver.getItemLabelByValue(RiskModDictEnum.risk_object, objectIdByRiskUnitId));
        excelVO.setRiskUnitId(DictResolver.getItemLabelByValue(RiskModDictEnum.risk_unit, entity.getRiskUnitId()));
        excelVO.setStopType(DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_stop_type, entity.getStopType()));
        return excelVO;
    }

    @Override
    public List<RiskUnitStopEntity> queryIsStopForList(RiskUnitStopBO riskUnitStop) {
        return this.baseMapper.queryIsStopForList(riskUnitStop);
    }

    @Override
    public IPage<RiskUnitStopVO> getRiskUnitStopPage(IPage<?> page, RiskUnitStopBO riskUnitStopBO) {
        return riskUnitStopMapper. getRiskUnitStopPage(page,riskUnitStopBO);
    }


}